/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package CreateTable;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author tashiba
 */
public class CreateTableNota {
    public static void main(String[] args) {

        try {
            try {
                Class.forName("com.mysql.jdbc.Driver");
            } catch (ClassNotFoundException ex) {
                Logger.getLogger(CreateTableUser.class.getName()).log(Level.SEVERE, null, ex);
            }
            Connection conn = DriverManager.getConnection("jdbc:mysql://localhost/pti", "root", "115314034");


            System.out.println("Koneksi is OK");
            Statement statement = conn.createStatement();
            String nota = " CREATE TABLE NOTA("
                    + "NO_NOTA VARCHAR(8) NOT NULL,"
                    + "TANGGAL DATE NOT NULL,"
                    + "NO_PENDAFTARAN VARCHAR(11) NOT NULL, "
                    + "NAMA_PASIEN VARCHAR(20) NOT NULL, "
                    + "ALAMAT_PASIEN VARCHAR(20) NOT NULL, "
                    + "NAMA_TINDAKAN VARCHAR(15),"
                    + "HARGA_TINDAKAN DOUBLE,"
                    + "TOTAL DOUBLE,"
                    + "CONSTRAINT NOTA_PK PRIMARY KEY (NO_NOTA),"
                    + "CONSTRAINT NOTA_FK1 FOREIGN KEY(NO_PENDAFTARAN)"
                    + "REFERENCES PENDAFTARAN(NO_PENDAFTARAN));";

            statement.executeUpdate(nota);
            System.out.println("Tabel NOTA Created");
        } catch (SQLException e) {
// perform error handling here
            System.out.println("error :" + e.getMessage());
        }
    }
}
